package com.yl.chainStore.entity.pay

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.common.Constants
import com.yl.chainStore.payrule.item.ItemRuleTypeEnum
import com.yl.common.annotation.NoArg
import java.math.BigDecimal
import java.math.RoundingMode
import java.util.*

/**
 * <p>
 *
 * </p>
 *
 * @author cxw
 * @since 2021-09-13
 */
@NoArg
@TableName("pay_customer_order_item_discount_rule_log")
data class PayCustomerOrderItemDiscountRuleLog(

	/**
	 * 订单项目优惠记录
	 */
	@TableId(value = "id", type = IdType.AUTO)
	var id: Long,

	/**
	 * 订单id
	 */
	@TableField("order_id")
	var orderId: Long,

	/**
	 * 详情id
	 */
	@TableField("detail_id")
	var detailId: Long,

	/**
	 * 内容
	 */
	@TableField("content")
	var content: String,

	/**
	 * 优惠类型
	 */
	@TableField("rule_type")
	var ruleType: ItemRuleTypeEnum = ItemRuleTypeEnum.DEFAULT,

	/**
	 * 创建时间（使用时间）
	 */
	@TableField("create_time")
	var createTime: Date? = Date(),

	/**
	 * 订单项目优惠id
	 * 101：手动划价
	 */
	@TableField("rule_id")
	var ruleId: Long,

	/**
	 * 折扣金额
	 */
	@TableField("discount_money")
	var discountMoney: Long =0
){
	@TableField(exist = false)
	var discountMoneyShow: BigDecimal?= null
		get() {

			if(field == null){
				return BigDecimal(discountMoney.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(2, RoundingMode.HALF_UP)
			}
			return field
		}
}
